﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Wicresoft.UnifyShow.Business;
using Microsoft.Practices.Unity;
using Wicresoft.UnifyShow.Portal.ViewModels;

namespace Wicresoft.UnifyShow.Portal.Controllers
{
    public class BESIncidentPartialViewController : BaseController
    {

        private IIncident incident;
        protected override void Dispose(bool disposing)
        {
            ((IDisposable)incident).Dispose();
        }

        [InjectionConstructor]
        public BESIncidentPartialViewController(IIncident incident)
        {
            this.incident = incident;
        }

        public ActionResult IncidentPartialView(int siteID, int serviceID, int? deviceID, int page = 1, string sort = "TicketCreateTime", string sortDir = "Descending")
        {
            const int pageSize = 10;
            Decimal totalCount = 0;
            PagedIncidentModel pim;
            List<IncidentModel> listIncident;
            if (deviceID.HasValue)
            {
                listIncident = incident.GetPageAndSortIncidentBySiteIDBSIDAndDeviceID(siteID, serviceID, deviceID.Value, out totalCount,
                    pageSize, page, sort, sortDir);
                pim = new PagedIncidentModel()
                {
                    PageNumber = page,
                    PageSize = pageSize,
                    TotalRows = totalCount,
                    Incidents = listIncident
                };

            }
            else
            {
                listIncident = incident.GetPageAndSortIncidentBySiteIDAndBSID(siteID, serviceID, out totalCount, pageSize, page, sort, sortDir);
                pim = new PagedIncidentModel()
                {
                    PageNumber = page,
                    PageSize = pageSize,
                    TotalRows = totalCount,
                    Incidents = listIncident
                };
            }
            return PartialView(pim);
        }

    }
}
